import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from "@angular/router";
import { UserListComponent } from "./user-list/user-list.component";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs/Observable";

@Injectable()
export class UserGuard implements CanDeactivate<any> {
    
    canDeactivate(component: UserListComponent, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
        console.log(component);
       if(!component.saved){
           return window.confirm("确定不保存吗？");
       }
       return true;
    }

}